#include <stdio.h>
#include <stdlib.h>

/* Constructor and Destructor Prototypes */

void main_constructor(void)
    __attribute__((no_instrument_function, constructor));

void main_destructor(void)
    __attribute__((no_instrument_function, destructor));

/* Output trace file pointer */
static FILE *fp;

void main_constructor(void)
{
    fp = fopen("trace.txt", "w");
    if (fp == NULL)
        exit(-1);
}

void main_deconstructor(void)
{
    fclose(fp);
}

void __attribute__((no_instrument_function)) __cyg_profile_func_enter(void *this, void *callsite)
{
    /* Function Entry Address */
    fprintf(fp, "E%#08x %#08x\n", (unsigned)this, (unsigned)callsite);
}

void __attribute__((no_instrument_function)) __cyg_profile_func_exit(void *this, void *callsite)
{
    /* Function Exit Address */
    fprintf(fp, "X%#08x %#08x\n", (unsigned)this, (unsigned)callsite);
}